package com.brandonflowers.hiveswfaddressdemo.states
{
	import com.brandonflowers.hiveswfaddressdemo.data.HiveDemoData;
	import flash.display.Shape;
	
	import org.hive.managers.plugin.LayoutManager;
	import org.hive.managers.StateManager;
	import org.hive.state.*;
	import org.hive.sequence.*;
	
	import com.brandonflowers.hiveswfaddressdemo.states.*;
	import flash.text.*;
	import flash.display.Sprite;
	
	public class ContactState extends State implements IState
	{
		private var contactBG	:Shape;
		private var contactTXT :TextField;
		private var contactContainer:Sprite;
		
		public override function create():ActionSequence
		{
			//________________________________________________________________________ ASSETS
			contactBG = new Shape();
			contactBG.graphics.beginFill(0x00CC00);
			contactBG.graphics.drawRect(0, 0, 400, 300);
			contactBG.x = 0;
			contactBG.y = 0;
						
			contactTXT = new TextField();
			
			var format:TextFormat = new TextFormat();
			format.color = 0x00CC00;
			format.size = 30;
			format.bold = true;
			format.font = "Helvetica";
			
			contactTXT = new TextField();
			contactTXT.embedFonts = true;
			contactTXT.autoSize = TextFieldAutoSize.LEFT;
			contactTXT.antiAliasType = AntiAliasType.ADVANCED;
			contactTXT.defaultTextFormat = format;
			contactTXT.selectable = false;
			contactTXT.mouseEnabled = false;
			
			contactTXT.text = "CONTACT";
			
			contactTXT.x = contactBG.x;
			contactTXT.y = contactBG.y + contactBG.height + 10;
			
			contactContainer = new Sprite();
						
			contactContainer.addChild(contactBG);
			contactContainer.addChild(contactTXT);
			
			contactContainer.alpha = 0;
			contactContainer.x = 40;
			contactContainer.y = 40;	
						
			//________________________________________________________________________ SEQUENCE
			var createSequence:ActionSequence = new ActionSequence( "contactState::createSequence" );
			createSequence.push( { scope:contactContainer, alpha:1, time:1, transition:"easeoutsine" } );
			createSequence.push( new SequenceDelay(1000) );
			createSequence.push( { scope:contactContainer, x:300, time:2, transition:"easeoutback" } );
			createSequence.push( new SequenceDelay(2000) );
			
			
			return createSequence;
		}

		private function kill():void
		{
			LayoutManager.removeChild( contactContainer );
		}
		
		public override function close():CloseSequence
		{
			var closeSequence:CloseSequence = new CloseSequence( "contactState::closeSequence" );
			
			closeSequence.push( {scope:contactContainer, alpha:0, y:contactContainer.y + 300, time:1} );
			closeSequence.push( new SequenceDelay(1000) );
			closeSequence.push( new SequenceFunction(this, kill) );
			
			return closeSequence;
		}
		
	}
	
}
